<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="3">
          <div>公司logo</div>
        </el-col>
        <el-col :span="18"> 电商后台管理系统 </el-col>
        <el-col :span="3">
          <el-button type="info" @click="loginOut">退出</el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <!-- 左侧栏 -->
      <el-aside :width="isCollapse? '65px' : '200px' ">
        <div class="collapse" @click='isCollapse=!isCollapse'>||||</div>
        <el-menu
         :collapse="isCollapse"
         :collapse-transition='false'
         :unique-opened='true'
          :default-active="$route.path"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#ffd04b"
          :router='true'
        >
          <el-submenu :index="item1.id+''" v-for='item1 in menus' :key='item1.id'>
            <template slot="title">
              <i class="el-icon-user"></i>
              <span>{{ item1.authName }}</span>
            </template>
            <el-menu-item :index="'/'+item2.path" v-for="item2 in item1.children" :key='item2.id'>
              <i class="iconfont icon-password mr5"></i>
              <span slot="title">{{ item2.authName }}</span>
            </el-menu-item>
          </el-submenu>

        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import {getMenusAPI} from '@/http/api'
export default {
  name: "Home",
  data() {
    return {
      isCollapse:false,
      menus:[]
    }
  },
  created() {
    //获取权限菜单
    this.getMenus()
  },
  methods: {
    //获取权限菜单方法
   async getMenus() {
      const res=await getMenusAPI()
      this.menus=res;
    },
    //退出
    loginOut() {
      //清除本地token
      sessionStorage.removeItem("token");
      //跳转到登录页
      this.$router.replace("/login");
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/mixin/index.scss";

.collapse {
  text-align: center;
  cursor: pointer;
}
.el-header {
  background: #333;
  color: #fff;
}

.el-aside {
  background: #333744;
}

.el-container {
  height: 100%;
  color: #fff;
}

.el-main {
  color: #000;
}

.el-col {
  //  border:1px solid #f00;
  height: 60px;
  @extend .flex_vh_center;
}

.el-menu {
  border-right: none;
}
</style>
